package com.j180.web_two.controller;

import com.j180.web_two.bean.ClasseBean;
import com.j180.web_two.bean.StudentBean;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

//在使用模板引擎时 不能使用restController注解
/**
 * 凡是templates下的页面必须通过控制器来进行跳转
 */
@Controller
public class ThymeleafController {
    //返回的string 就是页面的名字
    @RequestMapping("/hello")
    public  String  test(Model model){

        StudentBean studentBean = new StudentBean();
        studentBean.setId(100);
        studentBean.setName("hello thymeleaf");
        studentBean.setGender("男");

        ClasseBean classeBean = new ClasseBean();
        classeBean.setId(1);
        classeBean.setName("班级1");

        studentBean.setClasseBean(classeBean);

        model.addAttribute("stu",studentBean);
        model.addAttribute("id","two");

        return "show";

    }

    @RequestMapping("/showAll")
    public String  getAllStudents(Model model){

        StudentBean studentBean = new StudentBean();
        studentBean.setId(100);
        studentBean.setName("hello thymeleaf0");
        studentBean.setGender("男");
        studentBean.setAge(19);
        studentBean.setJoinTime(LocalDate.now());

        StudentBean studentBean2 = new StudentBean();
        studentBean2.setId(101);
        studentBean2.setName("hello thymeleaf1");
        studentBean2.setGender("男");
        studentBean2.setAge(16);
        studentBean2.setJoinTime(LocalDate.now());

        StudentBean studentBean3 = new StudentBean();
        studentBean3.setId(102);
        studentBean3.setName("hello thymeleaf2");
        studentBean3.setGender("男");
        studentBean3.setAge(21);
        studentBean3.setJoinTime(LocalDate.now());


        StudentBean studentBean4 = new StudentBean();
        studentBean4.setId(103);
        studentBean4.setName("hello thymeleaf3");
        studentBean4.setGender("男");
        studentBean4.setAge(16);
        studentBean4.setJoinTime(LocalDate.now());



        StudentBean studentBean5 = new StudentBean();
        studentBean5.setId(104);
        studentBean5.setName("hello thymeleaf4");
        studentBean5.setGender("男");
        studentBean5.setAge(26);
        studentBean5.setJoinTime(LocalDate.now());


        ClasseBean classeBean = new ClasseBean();
        classeBean.setId(1);
        classeBean.setName("班级1");
        ClasseBean classeBean2 = new ClasseBean();
        classeBean2.setId(2);
        classeBean2.setName("班级2");

        studentBean.setClasseBean(classeBean);
        studentBean2.setClasseBean(classeBean2);
        studentBean3.setClasseBean(classeBean2);
        studentBean4.setClasseBean(classeBean);
        studentBean5.setClasseBean(classeBean2);

        List<StudentBean> list = new ArrayList<>();
        list.add(studentBean);
        list.add(studentBean2);
        list.add(studentBean3);
        list.add(studentBean4);
        list.add(studentBean5);

        model.addAttribute("stus",list);

        return "showAll";
    }


}
